﻿using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.PersonalDetailsCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.PersonalDetailsCommandHandler;
using IntelligentAgriculture.WebAPI.Filter;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 个人设置控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AgricultureAuthorize]
    [AllowAnonymous]
    public class PersonalSettingController : ControllerBase
    {
        /// <summary>
        ///  Mediator
        /// </summary>
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"> Mediator</param>
        public PersonalSettingController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取个人信息
        /// </summary>
        /// <param name="uid"> 用户ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<PersonalDetailsOutput>> GetPersonalDetails(int uid)
        {
            var command = new GetPersonalDetailsCommand(uid);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="command"> 修改密码命令</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdatePassWord(UpdatePassWordCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}